'use strict'
const req = require('express/lib/request');
const fs = require('fs');
const {Ob} = require('sequelize')

const seq = require('../db/seq');

const files = fs.readdirSync(__dirname);
// console.log(files);  // 当前目录

const routeFiles = files.filter(item=>{
    return item.endsWith('.js') && item !== 'use.model.js'
})
// console.log(routeFiles); // 当前文件

const reultModel ={}

routeFiles.forEach(item=>{
    let modelName = item.replace('.js','');
    // console.log(modelName);  product user
    let model = require(__dirname + '/' + item)
    reultModel[modelName]= seq.define(modelName,model)
})

// console.log(reultModel); //{ product: product, user: user }
reultModel.sync = async()=>{
    return await seq.sync({force:true})
}

reultModel.Ob = Ob

module.exports = reultModel;
